package sh.wn36.vehiclemanage.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;
import sh.wn36.vehiclemanage.entity.Car;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import sh.wn36.vehiclemanage.vo.carInfo;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xk
 * @since 2021-04-26
 */
@Service
public interface CarMapper extends BaseMapper<Car> {

    @Select("SELECT car.* ,d1.text brand,d2.text model,d3.text color,d5.text dept,d6.text  state from car LEFT JOIN dictionary d1 on d1.id=car.car_brand LEFT JOIN dictionary d2 ON car.car_model=d2.id \n" +
            "LEFT JOIN dictionary d3 ON car.car_color=d3.id left JOIN dictionary d5 \n" +
            "on car.dept_id = d5.id LEFT JOIN dictionary d6 ON car.car_state = d6.id \n" +
            "LEFT JOIN car_pic ca ON car.id = ca.cid ${ew.customSqlSegment}")
    IPage<carInfo> selectAll(Page<carInfo> page, @Param(Constants.WRAPPER) QueryWrapper<carInfo> queryWrapper);


    @Select("SELECT * FROM car WHERE car.car_state = 38")
    List<Car> selectAll2();
@Update("UPDATE car c SET c.car_state = 37 where c.id =  #{id}")
    boolean setStatesToRepaired(@Param("id") Integer carId);
    @Update("UPDATE car c SET c.car_state = 38 where c.id =  #{id}")
    boolean setStatesToUseable(@Param("id") Integer carId);
}
